<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>index</title>
 
<!-- Required Stylesheets -->
<link href="<%=request.getContextPath()%>/css/bootstrap/bootstrap.min.css" rel="stylesheet">

<!-- Required Javascript -->
<script src="<%=request.getContextPath()%>/js/jquery-3.1.1.min.js"></script>
<script src="<%=request.getContextPath()%>/js/bootstrap/bootstrap-treeview.min.js"></script>
 <style>
       #tree{
          width:220px;
       }
    </style>
  </head>
  
  <body>
    <div id="tree"></div>
    <script type="text/javascript">
    $(function(){
    	$.ajax({
    		url:"<%=request.getContextPath()%>/mmenu_getRoleMenu?id=0",
    		dataType:"text",
    		success:function(data){
    			var tree = data;
    			//alert(tree);
    			$('#tree').treeview({data: tree});//,enableLinks:true
    			$('#tree').treeview('expandAll', { levels: 2, silent: true });
    			/*$('#tree').on('click',function(event){
    				alert($(event.target).find(".glyphicon").eq(0).html())
    				$(event.target).find(".glyphicon").eq(0).click();
    				})
    			 $('#tree').on('click', function(ndata){
    				alert($(this).)
    			} */
    			 $('#tree').on('nodeSelected', function(event, ndata) { 
    				//alert(ndata);
    				//alert(JSON.stringify(ndata));
    				if(ndata.href!=undefined&&ndata.href!=""){
	    				parent.main.location.href=ndata.href; 
	    				var select_node = $('#tree').treeview('getSelected');
	    				var unselect_node = $('#tree').treeview('getUnselected');
	    				for(var i=0;i<unselect_node.length;i++){
	    					unselect_node[i].backColor=undefined;
	    				}
	    				select_node[0].backColor='#428bca';
	    				select_node[0].state.selected=false;
    				}
    				
    				var nodes = $('#tree').treeview('getChecked');
    				//alert(JSON.stringify(nodes));
    			}); 
    		}
    	});
    });
    
    
   /*  function getTree() {
    	var tree=[
    	          {
    	        	  "text":"菜单管理",
    	              "nodes":[
    	                  {
    	                      "href":"product_num_check_getPagedCategoryProductNum",
    	                      
    	                      "text":"查看差异"
    	                  }
    	              ]
    	              
    	          }
    	      ];
    	return tree;
    } 
    $('#tree').treeview({data: getTree(),showCheckbox:true,highlightSelected:false});	
    $('#tree').on('nodeSelected', function(event, ndata) { 
		//alert(ndata);
		//alert(JSON.stringify(ndata));
		if(ndata.href!=undefined&&ndata.href!=""){
			parent.main.location.href=ndata.href; 
		}
	}); */
    </script>
  </body>
  
</html>
